<?php

namespace App\Http\Controllers\Index;

use App\Http\Controllers\Index\UserAuth;
use App\Serves\CartServe;
use App\Utils\Show;
use Illuminate\Http\Request;
use App\Serves\OrderServe;

class Order extends UserAuth
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
        echo 111;
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create(Request $request)
    {
        //
        $params = $request->all();
        $ids = $params['ids'];
        if(!$ids) return Show::error();
        try{
            $res = OrderServe::saveOrder($ids, $this->userId);
        }catch (\Exception $e){
            return Show::error();
         }

       if($res) return Show::success(200,$res,[]);

    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //



    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        echo $id;
        //获取订单数据
        $goods = OrderServe::getGoodsById($id);
        if(!empty($goods)){
//            var_dump($goods);
        }
        return view('index.order')->with(['goods'=>$goods]);

    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
